//---------------------------------------------------------------------
// Author: jachymko
//
// Description: StaticExpression tab expansion handler tests
//
// Creation Date: Jan 1, 2007
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using NUnit.Framework;
using Pscx.Commands;

namespace PscxUnitTests.TabExpansion
{
    [TestFixture]
    public class VariableExpressionTest : TabExpansionTestBase
    {
        [Test]
        public void ExpandScopedVariableName()
        {
            AssertExpansions("${Private:ExecutionCon", new string[]
            {
                "${Private:ExecutionContext}"
            });

            AssertExpansions("$GLOBAL:PSHO", new string[]
            {
                "$GLOBAL:PSHOME"
            });

            AssertExpansions("$sCrIpT:eRrOrACTIONprefer", new string[]
            {
                "$sCrIpT:ErrorActionPreference"
            });

        }

        [Test]
        public void ExpandProviderVariable()
        {
            AssertExpansions("${Env:Path", new string[]
            {
                "${Env:Path}",
                "${Env:PATHEXT}"
            });

            AssertExpansions("$Env:Path", new string[]
            {
                "$Env:Path",
                "$Env:PATHEXT"
            });
        }

        [Test]
        public void ExpandProviderNested()
        {
            AssertExpansions("${C:\\Windows\\System3", new string[]
            {
                "${C:\\Windows\\System32\\"
            });
        }

        [Test]
        public void ExpandProvider()
        {
            AssertExpansions("$Functio", new string[]
            {
                "$Function:"
            });

            AssertExpansions("${Variab", new string[]
            {
                "${Variable:"
            });
        }

        [Test]
        public void ExpandSimpleVariableName()
        {
            AssertExpansions("$DebugPrefere", new string[]
            {
                "$DebugPreference"
            });
        }

        [Test]
        public void ExpandStrangeVariableName()
        {
            Runspace.SessionStateProxy.SetVariable("'Strange'.Var-iable#Name", new object());

            AssertExpansions("${'Str", new string[]
            {
                "${'Strange'.Var-iable#Name}"
            });
        }

        [Test]
        public void ExpandPropertyExpression()
        {
            AssertExpansions("$Global:Host.Versio", new string[]
            {
                "$Global:Host.Version"
            });
        }

        [Test]
        public void ExpandMultiPropertyExpression()
        {
            AssertExpansions("$Global:host.ui.rawui.max", new string[]
            {
                "$Global:host.ui.rawui.MaxPhysicalWindowSize",
                "$Global:host.ui.rawui.MaxWindowSize"
            });
        }

        [Test]
        public void ExpandPropertyMethodExpression()
        {
            AssertExpansions("$Host.UI.w", new string[]
            {
                "$Host.UI.Write(",
                "$Host.UI.WriteDebugLine(",
                "$Host.UI.WriteErrorLine(",
                "$Host.UI.WriteLine(",
                "$Host.UI.WriteProgress(",
                "$Host.UI.WriteVerboseLine(",
                "$Host.UI.WriteWarningLine("
            });
        }

        [Test]
        public void ExpandAllMembers()
        {
            AssertExpansions("$host.version.", new string[]
            {
                "$host.version.Clone()",
                "$host.version.CompareTo(",
                "$host.version.Equals(",
                "$host.version.GetHashCode()",
                "$host.version.GetType()",
                "$host.version.ToString(",
                "$host.version.Build",
                "$host.version.Major",
                "$host.version.MajorRevision",
                "$host.version.Minor",
                "$host.version.MinorRevision",
                "$host.version.Revision",
                "$host.version.PSBase",
                "$host.version.PSObject",
            });
        }

        [Test]
        public void ExpandGetters()
        {
            AssertExpansions("$host.version.get_", new string[]
            {
                "$host.version.get_Build()",
                "$host.version.get_Major()",
                "$host.version.get_MajorRevision()",
                "$host.version.get_Minor()",
                "$host.version.get_MinorRevision()",
                "$host.version.get_Revision()",
            });
        }

        [Test]
        public void ExpandSetters()
        {
            AssertExpansions("$host.ui.rawui.set_", new string[]
            {
                "$host.ui.rawui.set_BackgroundColor(",
                "$host.ui.rawui.set_BufferSize(",
                "$host.ui.rawui.set_CursorPosition(",
                "$host.ui.rawui.set_CursorSize(",
                "$host.ui.rawui.set_ForegroundColor(",
                "$host.ui.rawui.set_WindowPosition(",
                "$host.ui.rawui.set_WindowSize(",
                "$host.ui.rawui.set_WindowTitle(",
            });
        }
    }
}
